package xj.toolkit.netty.util;

public enum ConsoleColor {
	NORMAL(Attributes.NORMAL), GREEN(Attributes.BOLD, Attributes.GREEN), CYAN(Attributes.BOLD, Attributes.CYAN), YELLOW(
			Attributes.BOLD, Attributes.YELLOW), RED(Attributes.BOLD, Attributes.RED), GREEN_WITH_RED_BG(
					Attributes.BOLD, Attributes.GREEN,
					Attributes.BG_RED), CYAN_WITH_BLUE_BG(Attributes.BOLD, Attributes.CYAN, Attributes.BG_BLUE);

	String color;

	ConsoleColor(Attributes... colors) {
		StringBuilder sb = new StringBuilder(ESCAPE_BEGIN);
		for (int i = 0; i < colors.length; i++) {
			sb.append(colors[i].value());
			if (i < colors.length - 1) {
				sb.append(";");
			}
		}
		sb.append(ESCAPE_END);
		color = sb.toString();
	}

	public String value() {
		return color;
	}

	public static final String ESCAPE_BEGIN = "\033[";
	public static final String ESCAPE_END = "m";

	public enum Attributes {
		NORMAL(0), BOLD(1), RED(31), GREEN(32), YELLOW(33), CYAN(36), BG_RED(41), BG_BLUE(44);

		int color;

		Attributes(int color) {
			this.color = color;
		}

		public int value() {
			return color;
		}
	}
}
